package cn.mw.cmdb.param.zabbixResult;

import cn.mw.cmdb.entity.ItemDropInfo;
import cn.mw.cmdb.param.QueryMonitorParam;
import cn.mw.components.mongodb.page.MWPage;
import com.alibaba.nacos.common.utils.CollectionUtils;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 监控历史数据
 */
@Data
public class MwMonitorHistoryParam extends QueryMonitorParam {
    @ApiModelProperty("时间类型，1：hour 2:day 3:week 4:month 5:自定义")
    private int dateType;
    @ApiModelProperty("当时间类型为 5:自定义时,开始时间")
    private String startDate;
    @ApiModelProperty("当时间类型为 5:自定义时,结束时间")
    private String endDate;
    //所选监控项信息
    private List<ItemDropInfo> itemInfos;
    //监控项设备
    private List<String> interfaceDrops;
    //应用集名称
    private String applicationName;
    //高级表格自定义接口名称
    @Schema(description = "自定义名称")
    private String customName;

    @ApiModelProperty("是否取趋势数据")
    private Boolean isTrend;
    @ApiModelProperty("资产状态")
    private String assetsStatus;
    //查询类型（详细/趋势）
    private String trendType;
    //组件类型
    private String chartType;
    //是否含有描述信息
    private boolean hasDescription;
    //查询条件字段名
    private String queryName;
    //查询条件字段值
    private String queryValue;
    @ApiModelProperty("排序的属性名称")
    private String sortField;
    @ApiModelProperty("0为升序；1为倒序")
    private int sortMode;
    @Schema(description = "分页查询参数,current当前页,size每页条数,默认20")
    private MWPage page;

    @Schema(description = "是否默认布局")
    private boolean defaultFlag;

    //监控项ids
    public List<String> getItemIdsDropInfos() {
        Set<String> set = new HashSet<>();
        if (CollectionUtils.isNotEmpty(itemInfos)) {
            for (ItemDropInfo itemDropInfo : itemInfos) {
                if(CollectionUtils.isNotEmpty(itemDropInfo.getItemids())){
                    set.addAll(itemDropInfo.getItemids());
                }else{
                    set.add(itemDropInfo.getItemid());
                }
            }
        }
        List<String> itemIds = new ArrayList<>(set);
        return itemIds;
    }
    //监控项名称
    public List<String> getItemNamesDropInfos() {
        Set<String> set = new HashSet<>();
        if (CollectionUtils.isNotEmpty(itemInfos)) {
            for (ItemDropInfo itemDropInfo : itemInfos) {
                set.add(itemDropInfo.getName());
            }
        }
        List<String> itemNames = new ArrayList<>(set);
        return itemNames;
    }
}
